<?php

/**
 * HTTP send response to client, and set headers.
 * @package Core
 * @category Core
 * @author kovacsricsi
 */
class HTTP
{
	/**
	 * Echo output.
	 * @access public
	 * @static
	 * @param AView $view
	 * @param string $header
	 * @return void
	 */
	static public function sendOutput(AView $view, $header)
	{
		if ($view->getTemplate() == "404.html") {
			$header = "404_headers.txt";
		}

		if ($fp = fopen(DIR_HEADERS . "/" . $header, "rb")) {
			while (!feof($fp))
			{
				self::sendHeader(fgets($fp), true);
			}
			fclose($fp);
		}

		echo($view->getOutput());
	}

	/**
	 * Send header.
	 * @access public
	 * @static
	 * @param string $header
	 * @param boolean $replace
	 * @param integer $code
	 * @return void
	 */
	public static function sendHeader($header, $replace, $code = 200)
	{
		header($header, $replace, $code);
	}

	/**
	 * Write string to output.
	 * @access public
	 * @static
	 * @param string $sring
	 * @return void
	 */
	public static function write($string)
	{
		echo (string)$string;
		flush();ob_flush();
	}
}

?>